package com.startrek.ch02;

public class BinarySearch {

    public boolean search(int[] a, int key) {
        int start = 0;
        int end = a.length - 1;
        while (start <= end) {
            int mid = (end - start) / 2 + start;
            if (a[mid] == key)
                return true;
            else if (a[mid] > key)
                end = mid - 1;
            else if (a[mid] < key)
                start = mid + 1;
        }

        return false;
    }

}
